<?php

namespace App\V3\V3_2_6\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class StorageShelfModel extends Model
{


    use HasFactory;

    protected $table = 'storage_shelf';
    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储
    protected $fillable = ['shelf_name','main_id','storage_id','created_at','updated_at','shelf_type'];

    const USEDSTATUS = 1;
    const DELETESTATUS = 0;

    const DEFAULTTYPE = 1; //默认类型标示
    const CREATETYPE = 2; //用户创建的类型标示

    //toArray 时间转换问题
    public static function createDefaultProductShelf($mainUserId, $storageId)
    {
        return self::insertGetId([
            'shelf_name' => '默认产品库货架',
            'is_product_shelf' => 1,
            'main_id' => $mainUserId,
            'storage_id' => $storageId,
            'created_at' => time(),
            'shelf_type' => 1
        ]);
    }

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function locations()
    {
        return $this->hasMany('App\V3\V3_2_6\Models\StorageShelfLocationModel','shelf_id','id');
    }

    public function locationList()
    {
        return self::hasMany(StorageShelfLocationModel::class, 'shelf_id', 'id');
    }
}
